package com.sql.parse.ognl;
import java.util.List;

/**
 * @author GWQ
 */
public class ChooseSqlNode implements DataNode {
  private DataNode defaultSqlNode;
  private List<DataNode> ifSqlNodes;

  public ChooseSqlNode(List<DataNode> ifSqlNodes, DataNode defaultSqlNode) {
    this.ifSqlNodes = ifSqlNodes;
    this.defaultSqlNode = defaultSqlNode;
  }

  @Override
  public boolean apply(MyDynamicContext context) {
    for (DataNode sqlNode : ifSqlNodes) {
      if (sqlNode.apply(context)) {
        return true;
      }
    }
    if (defaultSqlNode != null) {
      defaultSqlNode.apply(context);
      return true;
    }
    return false;
  }
}
